package com.liaoban.app.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.liaoban.app.R;
import com.liaoban.app.api.type.Rank;
import com.liaoban.app.helper.ImageHelper;
import com.liaoban.app.util.CommonUtils;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by ybc on 2018/7/16 0016.
 * 排行榜顶部九宫格
 */
public class RankChildTopAdapter extends BaseQuickAdapter<Rank, BaseViewHolder> {

    public RankChildTopAdapter(@Nullable List<Rank> data) {
        super(R.layout.item_rank_child_top, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Rank item) {
        CircleImageView ivIcon = helper.getView(R.id.iv_icon);
        ImageHelper.load(ivIcon, CommonUtils.getFullPic(item.getWuserSrc()));
        switch (helper.getLayoutPosition()) {
            case 0:
                helper.setText(R.id.tv_rank, (helper.getLayoutPosition() + 1) + "");
                helper.setBackgroundRes(R.id.tv_rank, R.mipmap.ic_rank_crow1);
                ivIcon.setBorderColor(mContext.getResources().getColor(R.color.btn_red));
                break;
            case 1:
                helper.setText(R.id.tv_rank, (helper.getLayoutPosition() + 1) + "");
                helper.setBackgroundRes(R.id.tv_rank, R.mipmap.ic_rank_crow2);
                ivIcon.setBorderColor(mContext.getResources().getColor(R.color.btn_yellow));
                break;
            case 2:
                helper.setText(R.id.tv_rank, (helper.getLayoutPosition() + 1) + "");
                helper.setBackgroundRes(R.id.tv_rank, R.mipmap.ic_rank_crow3);
                ivIcon.setBorderColor(mContext.getResources().getColor(R.color.btn_gray));
                break;
            case 3:
                helper.setText(R.id.tv_rank, (helper.getLayoutPosition() + 1) + "");
                helper.setBackgroundRes(R.id.tv_rank, R.mipmap.ic_rank_crow3);
                ivIcon.setBorderColor(mContext.getResources().getColor(R.color.btn_gray));
                break;

        }
        ImageView ivGrade = helper.getView(R.id.iv_grade);
        ImageHelper.load(ivGrade, CommonUtils.getRecommendGradeRes(item.getWuserGrade()));
        helper.setText(R.id.tv_name, item.getName());
        switch (item.getFansIsStatus()) {
            case 0:
                helper.setGone(R.id.iv_follow, true);
                helper.setImageResource(R.id.iv_follow, R.mipmap.ic_follow_she);
                break;
            case 1:
                helper.setGone(R.id.iv_follow, true);
                helper.setImageResource(R.id.iv_follow, R.mipmap.ic_has_follow);
                break;
            case 2:
                helper.setGone(R.id.iv_follow, true);
                helper.setImageResource(R.id.iv_follow, R.mipmap.ic_fh);
                break;
            case 3:
                helper.setGone(R.id.iv_follow, false);
        }
        switch (item.getLineStatus()) {
            case 1:
                helper.setBackgroundRes(R.id.tv_line_status, R.drawable.shape_yellow_oval);
                break;
            case 2:
                helper.setBackgroundRes(R.id.tv_line_status, R.drawable.shape_gray_oval);
                break;
            case 3:
                helper.setBackgroundRes(R.id.tv_line_status, R.drawable.shape_red_oval);
                break;
        }
        helper.addOnClickListener(R.id.iv_follow);
    }
}
